﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using System.Collections.ObjectModel;
using System.ComponentModel;


namespace AGameOfThrones.game
{
    public class game : INotifyPropertyChanged, stream.streamable
    {
        public Dictionary<String, piece> Pieces { get; set; }
        
        public game()
        {
            Pieces = new Dictionary<String, piece>();
        }
        
        private ObservableCollection<house> houses = new ObservableCollection<house>();
        public ObservableCollection<house> Houses
        {
            get { return houses; }
            set
            {
                if(houses != value)
                {
                    houses = value;
                    Notify("Houses");
                }
            }
        }
 
        public void serialize(stream.stream io_Stream)
        {
            io_Stream.begin("game");
            io_Stream.serialize("houses", ref houses);        
            io_Stream.end();
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void Notify(string property)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

        public void Initialize()
        {
            foreach (house h in Houses)
            {
                h.Initialize();
            }
        }
        
        public bool MovePiece(String in_Piece, position in_Position)
        {
            if (Pieces.ContainsKey(in_Piece))
            {
                piece p = Pieces[in_Piece];
                p.Position = in_Position;
                return true;
            }
            return false;
        }
    }
}
